package yoyosys;

import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.bson.Document;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

class TestDoc {
    private static String srcJson = "{\n" +
            "\t\"product\" : \"1\",\n" +
            "\t\"eventLevel\" : 1,\n" +
            "\t\"helmet\" : true,\n" +
            "\t\"trackingId\" : 111,\n" +
            "\t\"headImgPath\" : \"/miivii/20181101/0d7a08d41d2e48fab481917b79fcb29d\",\n" +
            "\t\"bodyImgPath\" : \"\",\n" +
            "\t\"invokeAiStatus\" : \"FAILED\",\n" +
            "\t\"errorCode\" : 222203,\n" +
            "\t\"stranger\" : true,\n" +
            "\t\"userId\" : 2323\n" +
            "}";
    private static DBObject bson = (DBObject) JSON.parse( srcJson );

    private static Date beginDate ;
    private static Date endDate;
    private Document doc;

    TestDoc() {
        try {
            SimpleDateFormat df = new SimpleDateFormat( "yyyyMMddhhmmss" );
            beginDate = df.parse( "20181001000000" );
            endDate = df.parse( "20181115000000" );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


     Document getDoc() {

        int n = (int) Util.random( 0, 5 );
        switch (n) {
            case 1:
                doc = getHelmet();
                break;
            case 2:
                doc = getTrack();
                break;
            case 3:
                doc = getInstrusion();
                break;
            case 4:
                doc = getFire();
                break;
        }
        return doc;
    }

    private Document getHelmet() {
        long dataL = Util.random( beginDate.getTime(), endDate.getTime() );
        int randNum =(int) (Math.random() * 10000);
        Date tmpDate = new Date( dataL );

        doc = new Document( (Map<String, Object>) bson );
        doc.append( "deviceId","MVB21V"+randNum);
        doc.append( "eventType", "personel manage" );
        doc.append( "eventSubtype", "safety helmet" );
        doc.append( "cameraId", "MVB21V" + randNum);
        doc.append( "eventTimestamp", tmpDate );
        doc.append( "createDateTime", tmpDate );
        return doc;
    }

    private Document getTrack() {
        long dataL = Util.random( beginDate.getTime(), endDate.getTime() );
        int randNum =(int) (Math.random() * 10000);
        Date tmpDate = new Date( dataL );

        doc = new Document( (Map<String, Object>) bson );
        doc.append( "deviceId","MVB21V"+randNum);
        doc.append( "eventType", "personel manage" );
        doc.append( "eventSubtype", "track" );
        doc.append( "cameraId", "MVB21V" + randNum);
        doc.append( "eventTimestamp", tmpDate );
        doc.append( "createDateTime", tmpDate );

        return doc;
    }

    private Document getInstrusion() {
        long dataL = Util.random( beginDate.getTime(), endDate.getTime() );
        int randNum =(int) (Math.random() * 10000);
        Date tmpDate = new Date( dataL );

        doc = new Document( (Map<String, Object>) bson );
        doc.append( "deviceId","MVB21V"+randNum);
        doc.append( "eventType", "security" );
        doc.append( "eventSubtype", "intrusion" );
        doc.append( "cameraId", "MVB21V" +randNum );
        doc.append( "eventTimestamp", tmpDate );
        doc.append( "createDateTime", tmpDate );
        return doc;
    }

    private Document getFire() {
        long dataL = Util.random( beginDate.getTime(), endDate.getTime() );
        int randNum =(int) (Math.random() * 10000);
        Date tmpDate = new Date( dataL );

        doc = new Document( (Map<String, Object>) bson );
        doc.append( "deviceId","MVB21V"+randNum);
        doc.append( "eventType", "security" );
        doc.append( "eventSubtype", "fire" );
        doc.append( "cameraId", "MVB21V" + randNum);
        doc.append( "eventTimestamp", tmpDate );
        doc.append( "createDateTime", tmpDate );
        return doc;
    }

}
